package org.slusk.thynwor.feedback;

import org.slusk.thynwor.corestructures.Environment;
import org.slusk.thynwor.util.Coordinates;

import com.anji.hyperneat.nd.NDFloatArray;
import com.anji.hyperneat.nd.NDFloatArray.MatrixIterator;

public class TdReinforcementProvider extends ReinforcementProvider {

	public TdReinforcementProvider(Environment environment) {
		super(environment);
	}
	
	protected NDFloatArray processFeedbackForReinforcement(double rewardFactor, Coordinates outputCoords) {
		NDFloatArray feedback = null;
		feedback = new NDFloatArray(3,3,1);
		feedback.clear();
		
		if (rewardFactor != 0) {

			//HACK
			for (MatrixIterator it = feedback.iterator(); it.hasNext(); it.next()) {
				if (rewardFactor > 0) {
					it.set(-0.1f);
				} else {
					it.set(0.2f);
				}
			}
			feedback.set(0.0f, 1,1,0);
			feedback.set((float) rewardFactor, outputCoords.x, outputCoords.y, 0);
		}
		
		return feedback;
	}

}
